import '@/scss/reset.scss';
import '@/scss/common.scss';
import '@/css/font-awesome.min.css';
import '@/scss/card.scss';
import './index.scss';
import 'lib/Swiper-2.7.6/dist/idangerous.swiper.css';

import $ from 'jquery';
import Swiper from '@/lib/Swiper-2.7.6/dist/idangerous.swiper.min.js';
import 'layui-layer/layer.js';
import '@/js/tab.js';

// *** 域名查询 ***
const domainQuery = {
  $form: $('#domain-query-form'),
  $changeBtn: $('input[name="domext-type"]'),
  $domainInput: $("#js-domain-input"),
  $domainSearch: $('#js-domain-search'),
  $domain: $('#domain-list'),
  init: function () {
    this.bindEvents()
  },
  bindEvents: function () {
    const t = this;

    // “全选、全不选、常用”切换
    $('input[name="domain-type"]').change(function () {
      let type = $(this).val();
      switch (type) {
        case 'all':
          t.$domain.find('input').prop('checked', 'checked');
          break;
        case 'none':
          t.$domain.find('input').prop('checked', '');
          break;
        case 'usual':
          t.$domain.find('input').prop('checked', '');
          t.$domain.find('input[data-type="usual"]').prop('checked', 'checked');
          break;
      }
    })

    // 查询按钮事件
    t.$domainSearch.on('click', function () {
      t.search();
    })
  },
  search: function () {
    const t = this;

    let domain = t.$domainInput.val();
    if (domain) {
      let $domainLabel = t.$domain.find('input[name="domain"]:checked');
      let suffix = [];
      if ($domainLabel.length > 0) {
        $domainLabel.each(function () {
          suffix.push($(this).val())
        })
        let suffixString = suffix.join(',');
        $('input[name="suffix"]').val(suffixString);
        t.$form.submit();
      } else {
        layer.alert('请勾选域名后缀')
      }
    } else {
      layer.alert('请填写域名，如yunfv')
    }
  }
}

$(document).ready(function () {
  let banner = new Swiper('.swiper-container', {
    loop: true,
    autoplay: 5000,
    simulateTouch: false,
    pagination: '.pagination',
    paginationClickable: true
  })
  domainQuery.init();

})